package javazy;

import java.util.ArrayList;
import javazy.Users;
import javazy.Goods;
import javazy.ShoppingCar;
class CartItemArray {
	Users user;
	int num;
	Goods goods;
	double OneSortPrice;

public CartItemArray(){
	
}
	public CartItemArray(Goods goods,int num,Users users) {
		this.goods = goods;
		this.num = num;
		this.OneSortPrice=goods.getPrice()*num;
		
		users.shoppingcart.cartitem.add(this);
		//user.cartitem.add(this);

	}

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

}
public interface ShoppingCarDAO{
	public void AddGoods(String name,int Num);
	public void RemoveGoods(String name);
	public void ChangeGoodsNum(int Num);
	


public abstract class ShoppingCartDAOArray implements ShoppingCarDAO{
	
	private Users users;
	public void ShoppingCartDaoArray(Users users){
		this.users = users;
	}

	ArrayList<CartItemArray> cartitem = new ArrayList();
	public void RemoveGoods(Goods goods){
		for(int i=0;i<cartitem.size();i++){
			//Goods e = info.get(i).GoodsName;

			if(goods.getGoodsName().equals(cartitem.get(i).goods.getGoodsName())){
				cartitem.remove(i);
			}
				
		}	
	}
	public void AddGoods(Goods goods,int addnum){
		int flag = 0;
		for(int i=0;i<cartitem.size();i++){
			if(goods.equals(cartitem.get(i).goods)){
			
				cartitem.get(i).num+=addnum;
				cartitem.get(i).OneSortPrice = cartitem.get(i).num*cartitem.get(i).goods.getPrice();
				flag=1;
			}
		}
		if(flag==0){
			user.cart=new CartItemArray(goods, addnum,user); 
		}
	}
	Users user;
}
}


